package com.customization.api.e9sso.cmd;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.customization.commons.Console;
import com.engine.common.biz.AbstractCommonCommand;
import com.engine.common.entity.BizLogContext;
import com.engine.core.interceptor.CommandContext;
import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.hrm.User;

import java.util.*;

public class getWorkflowBaseCmd extends AbstractCommonCommand<Map<String,Object>> {


    public getWorkflowBaseCmd(User user, Map<String,Object> params) {
        this.user = user;
        this.params = params;

    }

    @Override
    public BizLogContext getLogContext() {
        return null;
    }

    @Override
    public Map<String, Object> execute(CommandContext commandContext) {
        Console.log("输入参数params:"+params.toString());
        Map<String, Object> apidatas = new HashMap<String, Object>();
        apidatas.put("status",false);
        apidatas.put("msg","未查询到相关数据");

        RecordSet rs=new RecordSet();


        String requestid=Util.null2String(params.get("requestId"));


        if(requestid.equals("")){
            apidatas.put("status",false);
            apidatas.put("msg","必填参数不允许为空");
            return apidatas;
        }



        String [] res=requestid.split(",");
        String  requestidStr="'0'";
        for (String s:  res) {
            requestidStr+=",'"+s+"'";
        }
        String sql=" select * from  WORKFLOW_BASE where activeversionid is null or id in(select activeversionid from  WORKFLOW_BASE where activeversionid is not null group by activeversionid ) and WORKFLOWDESC like '%BZ%' ";
        rs.execute(sql);

        JSONArray data=new JSONArray();
        while (rs.next()){
            JSONObject qr = new JSONObject();
            qr.put("id",rs.getString("id"));//id
            qr.put("workflowname",rs.getString("workflowname"));//单据类型
            data.add(qr);
        }

        if(data.size()>0) {
            apidatas.put("data", data);
            apidatas.put("status",true);
            apidatas.put("msg","获取成功");
        }
        return apidatas;
    }



}
